package com.bawei.lifecycle_test;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;


import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;

/**
 * Lifecycle
 * 1.感知activity/fragment的生命周期，组件和activity/fragment解耦
 * 2.感知Service的生命周期，组件和Service解耦
 * 3.感知Application的生命周期，组件和Application解耦
 *
 * LifecycleObserver
 * LifecycleOwner:自定义LifecycleOwner，不是只能感知1 2 3
 *
 *
 *
 */
public class MainActivity extends AppCompatActivity {

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        requestPermissions(new String[]{
                "android.permission.ACCESS_COARSE_LOCATION",
                "android.permission.ACCESS_FINE_LOCATION"
        },101);

    }
    //启动服务
    public void start(View view) {
        startService(new Intent(MainActivity.this,MyLocationService.class));

    }
    //停止服务
    public void stop(View view) {
        stopService(new Intent(MainActivity.this,MyLocationService.class));
    }
}